<template>
  <j-modal title="离职" :width="600" :visible="visible" :confirmLoading="loading" switchFullscreen @cancel="handleCancel" @ok="handleOk">
    <a-form-model ref="ruleForm" :rules="rules" :model="form" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }">
      <a-form-model-item label="人员类型" prop="type">
        <a-select v-model="form.type" :disabled="isDisabled" placeholder="请选择" style="width:100%;">
          <a-select-option v-for="(item, key) in typeArr" :key="key" :value="item.value">{{ item.title }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="姓名" prop="name">
        <a-input v-model="form.name" :disabled="isDisabled" placeholder="请输入" />
      </a-form-model-item>
      <a-form-model-item label="身份证号" prop="identification">
        <a-input v-model="form.identification" placeholder="请输入" :disabled="isDisabled" />
      </a-form-model-item>
      <a-form-model-item label="性别" prop="gender">
        <a-select v-model="form.gender" placeholder="请选择" :disabled="isDisabled">
          <a-select-option value="1">男</a-select-option>
          <a-select-option value="2">女</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="离职原因" prop="reasonLeave">
        <a-select v-model="form.reasonLeave"  placeholder="请选择" style="width:100%;">
          <a-select-option v-for="(item, key) in reasonLeaveArr" :key="key" :value="item.value">{{ item.title }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="离职日期" prop="terminationDate">
        <a-date-picker v-model="form.terminationDate" style="width:100%;" showTime valueFormat="YYYY-MM-DD HH:mm:ss" placeholder="请选择" />
      </a-form-model-item>
    </a-form-model>
  </j-modal>
</template>
<script>
import { getDictItemsFromCache } from '@/api/api'
import * as employmentApi from '@/api/sjsk/help/employment.js'
export default {
  name: 'AddModal',
  data() {
    return {
      visible: false,
      form: {},
      typeArr: getDictItemsFromCache('personType'),
      reasonLeaveArr: getDictItemsFromCache('reasonLeave'),
      rules: {
        type: [{ required: true, message: '请选择' }],
        name: [{ required: true, message: '请输入' }],
        identification: [{ required: true, message: '请输入' }],
        gender: [{ required: true, message: '请选择' }],
        reasonLeave: [{ required: true, message: '请选择' }],
        terminationDate: [{ required: true, message: '请选择' }],
      },
      loading: false,
      isDisabled: true,
      id: ""
    }
  },
  async created() {
  },
  methods: {
    show(record) {
      this.visible = true
      this.form.id = record.id
      this.form.type = record.type
      this.form.name = record.name
      this.form.identification = record.identification
      this.form.gender = record.gender
    },
    handleCancel() {
      this.visible = false
    },
    handleOk() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.loading = true
          employmentApi.quit(this.form).then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok');
              this.visible = false
              this.loading = false
            } else {
              this.loading = false
              this.$message.warn(res.message)
            }
          })
            .catch(e => {
              this.loading = false
              this.$message.warn('请求失败！')
            })
        }
      })
    },
  },
}
</script>
<style lang="less" scoped>

</style>
